﻿using System;
using System.Collections.Generic;

namespace YArchitech.Plumbing
{
	public class HYPumpGroupOperationCurve : HYPumpOperationCurveData
	{
		public HYPumpGroupOperationCurve()
		{
			this.m_eCurveType = EPumpCurveType.ePumpCurve_H;
			this.m_PumpOwner = null;
		}

		public HYPumpGroupOperationCurve(EPumpCurveType curveType, HYGroupPumpData pPumpOwner)
		{
			this.m_eCurveType = curveType;
			this.m_PumpOwner = pPumpOwner;
		}

		public override void CalulateExtents()
		{
		}

		public void CalulateOriginExtents(ref HYPumpOperationCurveDataBase curveExtents)
		{
			if (this.m_PumpOwner == null || this.m_PumpOwner.m_arrData.Count < 1)
			{
				return;
			}
			HYPumpOperationCurveData curveAbout = this.m_PumpOwner.m_arrData[0].GetCurveAbout(this.m_eCurveType);
			bool flag = !curveAbout.IsEmpty();
			if (flag)
			{
				curveAbout.FixExtentsByFitCurve();
			}
			curveExtents.m_curveLeftPt = curveAbout.m_curveLeftPt;
			curveExtents.m_curveRightPt = curveAbout.m_curveRightPt;
			curveExtents.m_curveLowPt = curveAbout.m_curveLowPt;
			curveExtents.m_curveHighPt = curveAbout.m_curveHighPt;
			int count = this.m_PumpOwner.m_arrData.Count;
			for (int i = 1; i < count; i++)
			{
				HYPumpOperationCurveData curveAbout2 = this.m_PumpOwner.m_arrData[i].GetCurveAbout(this.m_eCurveType);
				curveAbout2.FixExtentsByFitCurve();
				if (!flag)
				{
					flag = !curveAbout2.IsEmpty();
					curveExtents.m_curveLeftPt = curveAbout2.m_curveLeftPt;
					curveExtents.m_curveRightPt = curveAbout2.m_curveRightPt;
					curveExtents.m_curveLowPt = curveAbout2.m_curveLowPt;
					curveExtents.m_curveHighPt = curveAbout2.m_curveHighPt;
				}
				else
				{
					if (curveAbout2.m_curveLeftPt.first < this.m_curveLeftPt.first)
					{
						curveExtents.m_curveLeftPt = curveAbout2.m_curveLeftPt;
					}
					else if (curveAbout2.m_curveRightPt.first > this.m_curveRightPt.first)
					{
						curveExtents.m_curveRightPt = curveAbout2.m_curveRightPt;
					}
					if (curveAbout2.m_curveLowPt.second < this.m_curveLowPt.second)
					{
						curveExtents.m_curveLowPt = curveAbout2.m_curveLowPt;
					}
					else if (curveAbout2.m_curveHighPt.second > this.m_curveHighPt.second)
					{
						curveExtents.m_curveHighPt = curveAbout2.m_curveHighPt;
					}
				}
			}
		}

		public void AnsysGroupHCurve()
		{
			if (this.m_PumpOwner == null)
			{
				return;
			}
			if (this.m_PumpOwner.m_arrData.Count < 1)
			{
				return;
			}
			Dictionary<string, stuSameCurve> dicOriginSameCurves = this.m_PumpOwner.m_dicOriginSameCurves;
			this.m_vecOperation.Clear();
			this.m_arrGroupCurve.Clear();
			HYPumpOperationCurveDataBase baseExtent = new HYPumpOperationCurveDataBase();
			this.CalulateOriginExtents(ref baseExtent);
			bool bIsParallel = this.m_PumpOwner.m_bIsParallel;
			this.m_vecOperation.Clear();
			if (bIsParallel)
			{
				this.AnsysGroupHCurve_Parallel(dicOriginSameCurves, baseExtent);
				return;
			}
			this.AnsysGroupHCurve_Series(dicOriginSameCurves, baseExtent);
		}

		public void AnsysGroupNCurve()
		{
			if (this.m_PumpOwner == null)
			{
				return;
			}
			if (this.m_PumpOwner.m_arrData.Count < 1)
			{
				return;
			}
			this.m_arrGroupCurve.Clear();
			if (this.m_PumpOwner.m_bIsParallel)
			{
				this.AnsysGroupNCurve_Parallel();
				return;
			}
			this.AnsysGroupNCurve_Series();
		}

		public void AnsysGroupECurve()
		{
			if (this.m_PumpOwner == null)
			{
				return;
			}
			if (this.m_PumpOwner.m_arrData.Count < 1)
			{
				return;
			}
			this.m_arrGroupCurve.Clear();
			List<HYPumpOperationCurveData> arrGroupCurve = this.m_PumpOwner.m_GroupCurve_H.m_arrGroupCurve;
			List<HYPumpOperationCurveData> arrGroupCurve2 = this.m_PumpOwner.m_GroupCurve_N.m_arrGroupCurve;
			if (arrGroupCurve.Count != arrGroupCurve2.Count)
			{
				return;
			}
			for (int i = 0; i < arrGroupCurve.Count; i++)
			{
				HYPumpOperationCurveData hypumpOperationCurveData = arrGroupCurve[i];
				HYPumpOperationCurveData hypumpOperationCurveData2 = arrGroupCurve2[i];
				List<stCurvePt> list = new List<stCurvePt>();
				HYPumpOperationCurveData hypumpOperationCurveData3 = new HYPumpOperationCurveData();
				double first = hypumpOperationCurveData.m_curveLeftPt.first;
				double num = (hypumpOperationCurveData.m_curveRightPt.first - first) / 4.0;
				for (int j = 0; j < 5; j++)
				{
					double num2 = first + (double)j * num;
					double dH = hypumpOperationCurveData.CalCurveValue(num2);
					double dN = hypumpOperationCurveData2.CalCurveValue(num2);
					double value = HYPumpGroupOperationCurve.GetEfficient(num2, dH, dN) * 100.0;
					list.Add(new stCurvePt(Math.Round(num2, 1), Math.Round(value, 1)));
				}
				hypumpOperationCurveData3.SetByPtCurveArr(ref list);
				hypumpOperationCurveData3.m_nTimes = this.m_PumpOwner.nECurveIndex;
				hypumpOperationCurveData3.m_efitMethod = _EFitMatrixMethod.eCompleteFill;
				hypumpOperationCurveData3.FitCurveParam();
				this.m_arrGroupCurve.Add(hypumpOperationCurveData3);
			}
		}

		public void AnsysGroupNPSHCurve()
		{
			if (this.m_PumpOwner == null)
			{
				return;
			}
			if (this.m_PumpOwner.m_arrData.Count < 1)
			{
				return;
			}
			this.m_arrGroupCurve.Clear();
			if (this.m_PumpOwner.m_bIsParallel)
			{
				this.AnsysGroupNPSHCurve_Parallel();
				return;
			}
			HYPumpOperationCurveData curveAbout = this.m_PumpOwner.m_arrData[0].GetCurveAbout(EPumpCurveType.ePumpCurve_NPSH);
			this.m_arrGroupCurve.Add(curveAbout);
		}

		public void UpdateSectionCacheByQ(List<HYPumpOperationCurveData> curveArrData)
		{
			if (this.m_vecOperation.Count < 1 || this.m_vecOperation.Count != curveArrData.Count)
			{
				return;
			}
			for (int i = 0; i < this.m_vecOperation.Count; i++)
			{
				this.m_vecOperation[i].m_dStart = curveArrData[i].m_curveLeftPt.first;
				this.m_vecOperation[i].m_dEnd = curveArrData[i].m_curveRightPt.first;
			}
		}

		public void AnsysGroupHCurve_Parallel(Dictionary<string, stuSameCurve> mapOrigin, HYPumpOperationCurveDataBase baseExtent)
		{
			Dictionary<double, stuSameCurve> dictionary = new Dictionary<double, stuSameCurve>();
			List<stuPumpOperationSection> list = new List<stuPumpOperationSection>();
			dictionary.Clear();
			foreach (KeyValuePair<string, stuSameCurve> keyValuePair in mapOrigin)
			{
				stuSameCurve value = keyValuePair.Value;
				this.UpdateSameCurve(ref value, EPumpCurveType.ePumpCurve_H, true);
				double key = value.m_combinedCurve.CalCurveValue(0.0);
				dictionary.Add(key, value);
			}
			List<stuSameCurve> list2 = new List<stuSameCurve>();
			bool flag = false;
			List<double> list3 = new List<double>(dictionary.Keys);
			for (int i = list3.Count - 1; i >= 0; i--)
			{
				double dQs = list3[i];
				double dQe;
				if (i <= 0)
				{
					dQe = baseExtent.m_curveLowPt.second;
					flag = true;
				}
				else
				{
					double second = dictionary[list3[i]].m_combinedCurve.m_curveLowPt.second;
					double num = list3[i - 1];
					if (num < second)
					{
						dQe = second;
						flag = true;
					}
					else
					{
						dQe = num;
					}
				}
				stuPumpOperationSection stuPumpOperationSection = new stuPumpOperationSection(dQs, dQe);
				list2.Add(dictionary[list3[i]]);
				stuPumpOperationSection.m_vecSameCurves = list2;
				list.Add(stuPumpOperationSection);
				if (flag)
				{
					break;
				}
			}
			this.m_vecOperation = list;
			bool flag2 = true;
			stCurvePt ptPreTail = new stCurvePt();
			this.m_arrGroupCurve.Clear();
			foreach (stuPumpOperationSection stuPumpOperationSection2 in this.m_vecOperation)
			{
				if (this.m_vecOperation.Count > 1 || stuPumpOperationSection2.m_vecSameCurves.Count > 1)
				{
					HYPumpOperationCurveData hypumpOperationCurveData = new HYPumpOperationCurveData();
					this.CombineCurveInRange_H(ref stuPumpOperationSection2.m_dStart, ref stuPumpOperationSection2.m_dEnd, stuPumpOperationSection2.m_vecSameCurves, true, !flag2, ptPreTail, ref hypumpOperationCurveData);
					this.m_arrGroupCurve.Add(hypumpOperationCurveData);
					ptPreTail = hypumpOperationCurveData.m_curveRightPt;
					flag2 = false;
				}
				else
				{
					if (stuPumpOperationSection2.m_vecSameCurves.Count > 0)
					{
						this.m_arrGroupCurve.Add(stuPumpOperationSection2.m_vecSameCurves[0].m_combinedCurve);
						break;
					}
					break;
				}
			}
		}

		public void AnsysGroupHCurve_Series(Dictionary<string, stuSameCurve> mapOrigin, HYPumpOperationCurveDataBase baseExtent)
		{
			double first = baseExtent.m_curveRightPt.first;
			stuPumpOperationSection stuPumpOperationSection = new stuPumpOperationSection();
			foreach (KeyValuePair<string, stuSameCurve> keyValuePair in mapOrigin)
			{
				HYPumpOperationCurveData pCurve = keyValuePair.Value.m_pCurve;
				if (pCurve.CalCurveValue(first) < 0.0)
				{
					pCurve.GetQbyValue(0.0, ref first, baseExtent.m_curveLeftPt.first, baseExtent.m_curveRightPt.first);
				}
				stuSameCurve value = keyValuePair.Value;
				this.UpdateSameCurve(ref value, EPumpCurveType.ePumpCurve_H, false);
				stuPumpOperationSection.m_vecSameCurves.Add(value);
			}
			stuPumpOperationSection.m_dStart = 0.0;
			stuPumpOperationSection.m_dEnd = first;
			this.m_vecOperation.Add(stuPumpOperationSection);
			if (this.m_vecOperation.Count < 1)
			{
				return;
			}
			List<stuSameCurve> vecSameCurves = this.m_vecOperation[0].m_vecSameCurves;
			if (vecSameCurves.Count == 1)
			{
				this.m_arrGroupCurve.Add(vecSameCurves[0].m_combinedCurve);
				return;
			}
			HYPumpOperationCurveData item = new HYPumpOperationCurveData();
			double num = 0.0;
			this.CombineCurveInRange_H(ref num, ref first, vecSameCurves, false, false, new stCurvePt(), ref item);
			this.m_arrGroupCurve.Add(item);
		}

		public void AnsysGroupNCurve_Parallel()
		{
			List<stuPumpOperationSection> vecOperation = this.m_PumpOwner.m_GroupCurve_H.m_vecOperation;
			List<HYPumpData> arrData = this.m_PumpOwner.m_arrData;
			List<HYPumpOperationCurveData> arrGroupCurve = this.m_PumpOwner.m_GroupCurve_H.m_arrGroupCurve;
			this.m_vecOperation.Clear();
			foreach (stuPumpOperationSection stuPumpOperationSection in vecOperation)
			{
				foreach (stuSameCurve stuSameCurve in stuPumpOperationSection.m_vecSameCurves)
				{
					HYPumpOperationCurveData curveAbout = arrData[stuSameCurve.m_nPumpArrIndex].GetCurveAbout(EPumpCurveType.ePumpCurve_N);
					stuSameCurve.m_pCurve = curveAbout;
				}
				this.m_vecOperation.Add(stuPumpOperationSection);
			}
			this.UpdateSectionCacheByQ(arrGroupCurve);
			bool flag = true;
			stCurvePt ptPreTail = new stCurvePt();
			this.m_arrGroupCurve.Clear();
			int num = 0;
			while (num < this.m_vecOperation.Count && num < vecOperation.Count)
			{
				stuPumpOperationSection stuPumpOperationSection2 = this.m_vecOperation[num];
				List<stuSameCurve> vecSameCurves = vecOperation[num].m_vecSameCurves;
				List<stuSameCurve> vecSameCurves2 = this.m_vecOperation[num].m_vecSameCurves;
				List<stuSameCurve> list = new List<stuSameCurve>();
				this.GetCurvesNotInArray(stuPumpOperationSection2.m_vecSameCurves, ref list);
				List<double> list2 = new List<double>();
				foreach (stuSameCurve stuSameCurve2 in list)
				{
					stuSameCurve2.m_pCurve = arrData[stuSameCurve2.m_nPumpArrIndex].GetCurveAbout(EPumpCurveType.ePumpCurve_N);
					HYPumpOperationCurveData pCurve = stuSameCurve2.m_pCurve;
					list2.Add(pCurve.CalCurveValue(0.0) * (double)stuSameCurve2.m_nCount);
				}
				if (this.m_vecOperation.Count > 1 || stuPumpOperationSection2.m_vecSameCurves.Count > 1)
				{
					HYPumpOperationCurveData hypumpOperationCurveData = new HYPumpOperationCurveData();
					this.CombineCurveInRange_N(stuPumpOperationSection2.m_dStart, stuPumpOperationSection2.m_dEnd, arrGroupCurve[num], vecSameCurves, vecSameCurves2, list2, true, !flag, ptPreTail, ref hypumpOperationCurveData);
					this.m_arrGroupCurve.Add(hypumpOperationCurveData);
					ptPreTail = hypumpOperationCurveData.m_curveRightPt;
				}
				else if (stuPumpOperationSection2.m_vecSameCurves.Count > 0)
				{
					stuSameCurve sameCurves = stuPumpOperationSection2.m_vecSameCurves[0];
					HYPumpOperationCurveData hypumpOperationCurveData2 = new HYPumpOperationCurveData();
					this.AnsysSameCurve(sameCurves, EPumpCurveType.ePumpCurve_N, true, ref hypumpOperationCurveData2);
					hypumpOperationCurveData2.FitCurveParam();
					this.m_arrGroupCurve.Add(hypumpOperationCurveData2);
					return;
				}
				flag = false;
				num++;
			}
		}

		public void AnsysGroupNCurve_Series()
		{
			List<stuPumpOperationSection> vecOperation = this.m_PumpOwner.m_GroupCurve_H.m_vecOperation;
			List<HYPumpData> arrData = this.m_PumpOwner.m_arrData;
			foreach (stuPumpOperationSection stuPumpOperationSection in vecOperation)
			{
				foreach (stuSameCurve stuSameCurve in stuPumpOperationSection.m_vecSameCurves)
				{
					stuSameCurve.m_pCurve = arrData[stuSameCurve.m_nPumpArrIndex].GetCurveAbout(EPumpCurveType.ePumpCurve_N);
				}
				this.m_vecOperation.Add(stuPumpOperationSection);
			}
			HYPumpOperationCurveData hcurve = new HYPumpOperationCurveData();
			bool flag = true;
			stCurvePt ptPreTail = new stCurvePt();
			this.m_arrGroupCurve.Clear();
			int num = 0;
			while (num < this.m_vecOperation.Count && num < vecOperation.Count)
			{
				stuPumpOperationSection stuPumpOperationSection3;
				stuPumpOperationSection stuPumpOperationSection2 = stuPumpOperationSection3 = this.m_vecOperation[num];
				List<stuSameCurve> vecSameCurves = vecOperation[num].m_vecSameCurves;
				List<stuSameCurve> vecSameCurves2 = stuPumpOperationSection2.m_vecSameCurves;
				List<double> otherArrZeroN = new List<double>();
				if (this.m_vecOperation.Count <= 1 && stuPumpOperationSection3.m_vecSameCurves.Count <= 1)
				{
					stuSameCurve sameCurves = stuPumpOperationSection3.m_vecSameCurves[0];
					HYPumpOperationCurveData hypumpOperationCurveData = new HYPumpOperationCurveData();
					this.AnsysSameCurve(sameCurves, EPumpCurveType.ePumpCurve_N, false, ref hypumpOperationCurveData);
					hypumpOperationCurveData.FitCurveParam();
					this.m_arrGroupCurve.Add(hypumpOperationCurveData);
					return;
				}
				HYPumpOperationCurveData hypumpOperationCurveData2 = new HYPumpOperationCurveData();
				this.CombineCurveInRange_N(stuPumpOperationSection3.m_dStart, stuPumpOperationSection3.m_dEnd, hcurve, vecSameCurves, vecSameCurves2, otherArrZeroN, false, !flag, ptPreTail, ref hypumpOperationCurveData2);
				this.m_arrGroupCurve.Add(hypumpOperationCurveData2);
				ptPreTail = hypumpOperationCurveData2.m_curveRightPt;
				flag = false;
				num++;
			}
		}

		public void AnsysGroupNPSHCurve_Parallel()
		{
			List<stuPumpOperationSection> vecOperation = this.m_PumpOwner.m_GroupCurve_H.m_vecOperation;
			List<HYPumpData> arrData = this.m_PumpOwner.m_arrData;
			Dictionary<string, stuSameCurve> dicOriginSameCurves = this.m_PumpOwner.m_dicOriginSameCurves;
			List<HYPumpOperationCurveData> arrGroupCurve = this.m_PumpOwner.m_GroupCurve_H.m_arrGroupCurve;
			if (vecOperation.Count < 1 || arrData.Count < 1)
			{
				return;
			}
			bool flag = arrData[0].eVacuumType == EVacuumType.EPVacuum_NPSH;
			this.m_vecOperation.Clear();
			bool flag2 = true;
			foreach (stuPumpOperationSection stuPumpOperationSection in vecOperation)
			{
				foreach (stuSameCurve stuSameCurve in stuPumpOperationSection.m_vecSameCurves)
				{
					stuSameCurve.m_pCurve = arrData[stuSameCurve.m_nPumpArrIndex].GetCurveAbout(EPumpCurveType.ePumpCurve_NPSH);
					if (stuSameCurve.m_pCurve.IsEmpty())
					{
						flag2 = false;
						break;
					}
				}
				if (!flag2)
				{
					break;
				}
				this.m_vecOperation.Add(stuPumpOperationSection);
			}
			if (dicOriginSameCurves.Count == 1)
			{
				Dictionary<string, stuSameCurve>.Enumerator enumerator3 = dicOriginSameCurves.GetEnumerator();
				if (!enumerator3.MoveNext())
				{
					return;
				}
				KeyValuePair<string, stuSameCurve> keyValuePair = enumerator3.Current;
				stuSameCurve value = keyValuePair.Value;
				value.m_pCurve = arrData[keyValuePair.Value.m_nPumpArrIndex].GetCurveAbout(EPumpCurveType.ePumpCurve_NPSH);
				HYPumpOperationCurveData item = new HYPumpOperationCurveData();
				this.AnsysSameCurve(value, EPumpCurveType.ePumpCurve_NPSH, true, ref item);
				this.m_arrGroupCurve.Add(item);
				return;
			}
			else
			{
				if (!flag2)
				{
					this.m_vecOperation.Clear();
					return;
				}
				this.UpdateSectionCacheByQ(arrGroupCurve);
				bool flag3 = true;
				stCurvePt item2 = new stCurvePt();
				int num = 0;
				while (num < vecOperation.Count && num < this.m_vecOperation.Count && num < arrGroupCurve.Count)
				{
					stuPumpOperationSection stuPumpOperationSection2 = vecOperation[num];
					stuPumpOperationSection stuPumpOperationSection3 = this.m_vecOperation[num];
					double dStart = stuPumpOperationSection3.m_dStart;
					double dEnd = stuPumpOperationSection3.m_dEnd;
					List<stuSameCurve> vecSameCurves = stuPumpOperationSection3.m_vecSameCurves;
					List<stuSameCurve> vecSameCurves2 = stuPumpOperationSection2.m_vecSameCurves;
					HYPumpOperationCurveData hypumpOperationCurveData = arrGroupCurve[num];
					double num2 = (dEnd - dStart) / 4.0;
					List<stCurvePt> list = new List<stCurvePt>();
					if (!flag3)
					{
						list.Add(item2);
					}
					for (int i = flag3 ? 0 : 1; i < 5; i++)
					{
						double num3 = dStart + (double)i * num2;
						double dValue = hypumpOperationCurveData.CalCurveValue(num3);
						double num4 = -1.0;
						int num5 = 0;
						while (num5 < vecSameCurves.Count && num5 < vecSameCurves2.Count)
						{
							stuSameCurve stuSameCurve2 = vecSameCurves[num5];
							stuSameCurve stuSameCurve3 = vecSameCurves2[num5];
							double dPtX = 0.0;
							if (stuSameCurve3.m_pCurve.GetQbyValue(dValue, ref dPtX, -1.0, -1.0) && !stuSameCurve2.m_pCurve.IsEmpty())
							{
								double num6 = stuSameCurve2.m_pCurve.CalCurveValue(dPtX);
								if (num4 < 0.0)
								{
									num4 = num6;
								}
								else if (num6 > num4 && flag)
								{
									num4 = num6;
								}
								else if (num6 < num4 && !flag)
								{
									num4 = num6;
								}
							}
							num5++;
						}
						num4 = ((num4 > 0.0) ? num4 : 0.0);
						list.Add(new stCurvePt(num3, num4));
					}
					HYPumpOperationCurveData hypumpOperationCurveData2 = new HYPumpOperationCurveData();
					hypumpOperationCurveData2.SetByPtCurveArr(ref list);
					hypumpOperationCurveData2.m_nTimes = this.m_PumpOwner.nNPSHCurveIndex;
					hypumpOperationCurveData2.FitCurveParam();
					this.m_arrGroupCurve.Add(hypumpOperationCurveData2);
					flag3 = false;
					item2 = hypumpOperationCurveData2.m_curveRightPt;
					num++;
				}
				return;
			}
		}

		public void AnsysSameCurve(stuSameCurve sameCurves, EPumpCurveType ecurvetype, bool bIsParallel, ref HYPumpOperationCurveData newcurve)
		{
			if (sameCurves.m_pCurve == null || sameCurves.m_pCurve.IsEmpty())
			{
				return;
			}
			List<stCurvePt> list = new List<stCurvePt>();
			sameCurves.m_pCurve.GetSortedPtCurveArr(ref list);
			List<stCurvePt> list2 = new List<stCurvePt>();
			for (int i = 0; i < list.Count; i++)
			{
				stCurvePt stCurvePt = list[i].New();
				if (bIsParallel)
				{
					stCurvePt.first *= (double)sameCurves.m_nCount;
				}
				switch (ecurvetype)
				{
				case EPumpCurveType.ePumpCurve_H:
					if (!bIsParallel)
					{
						stCurvePt.second *= (double)sameCurves.m_nCount;
					}
					break;
				case EPumpCurveType.ePumpCurve_N:
					stCurvePt.second *= (double)sameCurves.m_nCount;
					break;
				}
				list2.Add(stCurvePt);
			}
			newcurve.SetByPtCurveArr(ref list2);
			newcurve.m_nTimes = sameCurves.m_pCurve.m_nTimes;
			newcurve.m_efitMethod = _EFitMatrixMethod.eCompleteFill;
		}

		public void UpdateSameCurve(ref stuSameCurve sameCurves, EPumpCurveType ecurvetype, bool bIsParallel)
		{
			sameCurves.m_combinedCurve.Clear();
			this.AnsysSameCurve(sameCurves, ecurvetype, bIsParallel, ref sameCurves.m_combinedCurve);
			sameCurves.m_combinedCurve.FitCurveParam();
		}

		public void CombineCurveInRange_H(ref double dStart, ref double dEnd, List<stuSameCurve> arrCurves, bool bIsparallel, bool bConnect, stCurvePt ptPreTail, ref HYPumpOperationCurveData newcurve)
		{
			int nHCurveIndex = this.m_PumpOwner.nHCurveIndex;
			if (arrCurves == null || arrCurves.Count < 1)
			{
				return;
			}
			HYPumpOperationCurveData combinedCurve = arrCurves[0].m_combinedCurve;
			double num = (dStart > dEnd) ? dStart : dEnd;
			double num2 = (dStart < dEnd) ? dStart : dEnd;
			int num3 = 5;
			List<stCurvePt> list = new List<stCurvePt>();
			double num4 = (num - num2) / (double)(num3 - 1);
			for (int i = 0; i < num3; i++)
			{
				bool flag = true;
				double num5 = num2 + (double)i * num4;
				double num6 = 0.0;
				if (bIsparallel)
				{
					if (!combinedCurve.GetQbyValue(num5, ref num6, -1.0, -1.0))
					{
						flag = false;
					}
				}
				else
				{
					num6 = num5;
					num5 = combinedCurve.CalCurveValue(num6);
				}
				if (flag)
				{
					stCurvePt stCurvePt = new stCurvePt();
					stCurvePt.first = num6;
					stCurvePt.second = num5;
					list.Add(stCurvePt);
				}
			}
			if (arrCurves.Count > 1)
			{
				for (int j = 1; j < arrCurves.Count; j++)
				{
					HYPumpOperationCurveData combinedCurve2 = arrCurves[j].m_combinedCurve;
					for (int i = 0; i < list.Count; i++)
					{
						double num7 = num2 + (double)i * num4;
						double num8 = 0.0;
						if (bIsparallel)
						{
							combinedCurve2.GetQbyValue(num7, ref num8, -1.0, -1.0);
							list[i].first += num8;
						}
						else
						{
							num8 = num7;
							num7 = combinedCurve2.CalCurveValue(num8);
							list[i].second += num7;
						}
					}
				}
			}
			HYPumpOperationCurveData hypumpOperationCurveData = new HYPumpOperationCurveData();
			hypumpOperationCurveData.SetByPtCurveArr(ref list);
			hypumpOperationCurveData.m_nTimes = nHCurveIndex;
			hypumpOperationCurveData.m_efitMethod = _EFitMatrixMethod.eCompleteFill;
			hypumpOperationCurveData.FitCurveParam();
			double first = hypumpOperationCurveData.m_curveLeftPt.first;
			double num9 = (hypumpOperationCurveData.m_curveRightPt.first - first) / (double)(num3 - 1);
			list.Clear();
			if (bConnect)
			{
				list.Add(ptPreTail);
			}
			for (int i = bConnect ? 1 : 0; i < num3; i++)
			{
				stCurvePt stCurvePt2 = new stCurvePt();
				stCurvePt2.first = first + (double)i * num9;
				stCurvePt2.second = hypumpOperationCurveData.CalCurveValue(stCurvePt2.first);
				list.Add(stCurvePt2);
			}
			newcurve.SetByPtCurveArr(ref list);
			newcurve.m_nTimes = nHCurveIndex;
			newcurve.m_efitMethod = _EFitMatrixMethod.eCompleteFill;
			newcurve.FitCurveParam();
			if (bConnect)
			{
				dStart = ptPreTail.second;
			}
			else
			{
				dStart = newcurve.m_curveLeftPt.second;
			}
			dEnd = newcurve.m_curveRightPt.second;
		}

		public void GetCurvesNotInArray(List<stuSameCurve> curveArr, ref List<stuSameCurve> outPutArr)
		{
			foreach (KeyValuePair<string, stuSameCurve> keyValuePair in this.m_PumpOwner.m_dicOriginSameCurves)
			{
				using (List<stuSameCurve>.Enumerator enumerator2 = curveArr.GetEnumerator())
				{
					while (enumerator2.MoveNext())
					{
						if (enumerator2.Current.m_nPumpArrIndex == keyValuePair.Value.m_nPumpArrIndex)
						{
							outPutArr.Add(keyValuePair.Value);
							break;
						}
					}
				}
			}
		}

		public void CombineCurveInRange_N(double dStart, double dEnd, HYPumpOperationCurveData HCurve, List<stuSameCurve> singleHCurves, List<stuSameCurve> singleNCurves, List<double> otherArrZeroN, bool bIsParallel, bool bConnect, stCurvePt ptPreTail, ref HYPumpOperationCurveData newcurve)
		{
			double num = (dStart > dEnd) ? dStart : dEnd;
			double num2 = (dStart < dEnd) ? dStart : dEnd;
			int num3 = 5;
			double num4 = (num - num2) / (double)(num3 - 1);
			List<stCurvePt> list = new List<stCurvePt>();
			for (int i = 0; i < num3; i++)
			{
				list.Add(new stCurvePt());
			}
			if (bConnect)
			{
				list[0] = ptPreTail;
			}
			int num5 = bConnect ? 1 : 0;
			List<stCurvePt> list2 = new List<stCurvePt>();
			if (bIsParallel)
			{
				for (int j = 0; j < num3; j++)
				{
					double num6 = num2 + (double)j * num4;
					list2.Add(new stCurvePt(num6, HCurve.CalCurveValue(num6)));
				}
			}
			int k = 0;
			while (k < singleNCurves.Count && k < singleHCurves.Count)
			{
				HYPumpOperationCurveData pCurve = singleNCurves[k].m_pCurve;
				HYPumpOperationCurveData pCurve2 = singleHCurves[k].m_pCurve;
				for (int j = bConnect ? 1 : 0; j < num3; j++)
				{
					stCurvePt stCurvePt = list[j];
					double num7 = 0.0;
					if (bIsParallel)
					{
						double second = list2[j].second;
						if (stCurvePt.first >= 0.0 && pCurve2.GetQbyValue(second, ref num7, -1.0, -1.0))
						{
							stCurvePt.first = num7;
							stCurvePt.second += pCurve.CalCurveValue(num7) * (double)singleNCurves[k].m_nCount;
						}
						else
						{
							stCurvePt.first = -1.0;
						}
					}
					else
					{
						num7 = num2 + (double)j * num4;
						stCurvePt.first = num7;
						stCurvePt.second += pCurve.CalCurveValue(num7) * (double)singleNCurves[k].m_nCount;
					}
				}
				k++;
			}
			if (bIsParallel)
			{
				for (k = 0; k < otherArrZeroN.Count; k++)
				{
					double num8 = otherArrZeroN[k];
					for (int j = bConnect ? 1 : 0; j < num3; j++)
					{
						stCurvePt stCurvePt2 = list[j];
						if (stCurvePt2.first >= 0.0)
						{
							stCurvePt2.second += num8;
						}
					}
				}
			}
			List<stCurvePt> list3 = new List<stCurvePt>();
			for (int l = 0; l < list.Count; l++)
			{
				stCurvePt stCurvePt3 = list[l];
				if (bIsParallel)
				{
					stCurvePt3.first = list2[l].first;
					if (stCurvePt3.first > -ConstantValue.ITOR_TOLERANCERANGE)
					{
						list3.Add(stCurvePt3);
					}
				}
				else
				{
					list3.Add(stCurvePt3);
				}
			}
			newcurve.SetByPtCurveArr(ref list3);
			newcurve.m_nTimes = 3;
			newcurve.m_efitMethod = _EFitMatrixMethod.eCompleteFill;
			newcurve.FitCurveParam();
		}

		public static double GetEfficient(double dQ, double dH, double dN)
		{
			return 9806.65 * dQ * dH / (1000.0 * dN * 3600.0);
		}

		public List<HYPumpOperationCurveData> m_arrGroupCurve = new List<HYPumpOperationCurveData>();

		public EPumpCurveType m_eCurveType;

		public HYGroupPumpData m_PumpOwner;

		private List<stuPumpOperationSection> m_vecOperation = new List<stuPumpOperationSection>();
	}
}
